//package com.seeyon.apps.kkSample.utils.cap4;
//
//import com.seeyon.cap4.batch.params.BatchRefreshParams;
//import com.seeyon.cap4.batch.service.CAPBatchRefreshService;
//import com.seeyon.cap4.form.bean.FormBean;
//import com.seeyon.ctp.common.AppContext;
//import com.seeyon.ctp.common.GlobalNames;
//import com.seeyon.ctp.common.authenticate.domain.User;
//import com.seeyon.ctp.common.base.result.ServiceResult;
//import com.seeyon.ctp.common.exceptions.BusinessException;
//import com.seeyon.ctp.common.flag.BrowserEnum;
//import com.seeyon.ctp.common.i18n.LocaleContext;
//import com.seeyon.ctp.organization.bo.V3xOrgMember;
//import com.seeyon.ctp.organization.manager.OrgManager;
//import com.seeyon.ctp.util.json.JSONUtil;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
///**
// * 描述:底表批量刷新
// *
// * @author zjx
// * @Date 2020-10-28 15:03:24
// *
// */
//public class BatchRefreshUtil {
//
//	private static final Log log = LogFactory.getLog(BatchRefreshUtil.class);
//	private static CAPBatchRefreshService capBatchRefreshService = null;
//	private static OrgManager orgManager = null;
//
//	public static CAPBatchRefreshService getCAPBatchRefreshService() {
//		if (capBatchRefreshService == null) {
//			capBatchRefreshService = (CAPBatchRefreshService) AppContext.getBean("capBatchRefreshService");
//		}
//		return capBatchRefreshService;
//	}
//
//	public static OrgManager getOrgManager() {
//		if (orgManager == null) {
//			orgManager = (OrgManager) AppContext.getBean("orgManager");
//		}
//		return orgManager;
//	}
//
//	/**
//	 * 设置当前人员
//	 *
//	 * @param member
//	 * @throws BusinessException
//	 */
//	public static void setCurrentUser(String member) throws BusinessException {
//		User user = new User();
//		V3xOrgMember currentUser = null;
//		try {
//			currentUser = getOrgManager().getMemberByLoginName(member);
//			if (currentUser == null) {
//				currentUser = getOrgManager().getMemberById(Long.valueOf(member));
//			}
//		} catch (Exception e) {
//			currentUser = getOrgManager().getMemberByLoginName(member);
//		}
//		if (currentUser != null) {
//			user.setId(currentUser.getId());
//			user.setUserAgentFrom("pc");
//			user.setLoginName(currentUser.getLoginName());
//			user.setName(currentUser.getName());
//			user.setAccountId(currentUser.getOrgAccountId());
//			user.setBrowser(BrowserEnum.IE);
//			user.setLoginAccount(currentUser.getOrgAccountId());
//			user.setLocale(LocaleContext.getAllLocales().get(0));
//			user.setRemoteAddr("127.0.0.1");
//		} else {
//			user.setName("rest-api");
//			user.setLocale(LocaleContext.getAllLocales().get(0));
//			user.setRemoteAddr("127.0.0.1");
//		}
//		AppContext.putThreadContext(GlobalNames.SESSION_CONTEXT_USERINFO_KEY, user);
//	}
//
//	/**
//	 * 刷新表单公式
//	 *
//	 * @return
//	 */
//	public static ServiceResult<?> updateBatchRefreshData(String loginName,FormBean fb, List<String> masterIds) {
//		try {
//			//设置当前人员
//			if(StringUtils.isNotBlank(loginName)) {
//				 setCurrentUser(loginName);
//			}
//			// 刷新底表将数据带入
//			Long moduleId = fb.getAllModuleAuthList().get(0).getModuleId();
//			// 组装参数
//			BatchRefreshParams batchRefreshParams = new BatchRefreshParams();
//			batchRefreshParams.setFormId(fb.getId());
//			batchRefreshParams.setBindAuthId(moduleId);
//			batchRefreshParams.setSize(masterIds == null ? 0 : masterIds.size());
//			batchRefreshParams.setExecuteRelation(true);
//			batchRefreshParams.setUserOrderBy(null);
//			batchRefreshParams.setMasterIds(masterIds);
//			batchRefreshParams.setDataConditions(new ArrayList<Map<String, Object>>());
//			ServiceResult<?> ret = getCAPBatchRefreshService().batchRefresh(batchRefreshParams);
//			String toJSON = JSONUtil.toJSONString4Ajax(ret.toMap());
//			log.info("自动刷新底表情况:" + toJSON);
//			return ret;
//		} catch (Exception e) {
//			log.info("客开: 刷新底表数据失败!" + e);
//		}
//		return null;
//	}
//}
